<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>客户申请记录管理</title>
	<meta name="decorator" content="default"/>
	<style>
	.table-striped tbody>tr:nth-child(odd)>td, .table-striped tbody>tr:nth-child(odd)>th {
		background: none !important;
	}

	</style>
	<script src="${ctxStatic}/layer/layer.js"></script>
	<script src="${ctxStatic}/js/widget/stickytableheaders/js/jquery.stickytableheaders.min.js"></script>
	<script type="text/javascript">
		var loanMap={};
		layer.config({offset: ['300px', '400px']});
		$(document).ready(function() {
			$(".view_service_record").click(function(){
				var id=$(this).data("id");
				parent.layer.open({
					type: 2,
					title: '服务记录',
					shadeClose: true,
					shade: 0,
					area: ['90%', '70%'],
					content: '${ctx}/sys/member/member/seviceRecordPage?id='+id //iframe的url
				});
			});
			//查看客户信息
			$(".view-info").click(function(){
				var id=$(this).data("id");
				layer.open({
					type: 2,
					title:"客户信息",
					skin: 'layui-layer-rim', //加上边框
					offset: ['50px', '100px'],
					area: ['900px', '500px'], //宽高
					content: "${ctx}/sys/loan/customPay/load/viewMemberInfoPage?id="+id
				});
			});
			$(".do-pay").click(function(){
				if($(this).closest("td").find(".set-pay").length>0){
					layer.alert("操作失败，请先设置订金哦！");
					return;
				}
				if($(this).closest("td").find(".set-rate").length>0){
					layer.alert("操作失败，请先设置利率哦！");
					return;
				}
				var id=$(this).data("id");
				var sc=$(this).data("sc");
				if(!id||!sc){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				var html="";
				html+="<div style='padding: 10px;' id='sc_wrap'>";
				html+="<div>所需订金为："+sc/100+"元</div>";
				html+="<div><span style='color: red'>(*注：订金为0则客户无需支付定金)</span></div>";
				html+=	'<div class="row" style="display: block;margin: 0 auto;width: 200px;margin-top: 30px;">';
				html+=		'<input id="btn_save_do_pay" data-id="'+id+'" data-sc="'+sc+'" class="btn btn-primary" type="submit" value="确认付款"/>&nbsp;&nbsp;&nbsp;';
				html+=		'<input id="btn_cancel_sc" class="btn" type="button" value="取消" />';
				html+='</div>';
				html+="</div>"
				//页面层
            	layer.open({
            	  type: 1,
            	  title:"付订金",
            	  skin: 'layui-layer-rim', //加上边框
            	  area: ['350px', '200px'], //宽高
            	  content: html
            	});
			});
			$(".set-rate").click(function(){
				var id=$(this).data("id");
				if(!id){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				var loanid=$(this).data("loanid");
				if(!loanid){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				if(!(loanid in loanMap) ){
					$.ajax({
						type : "POST",  //提交方式
						url : "${ctx}/sys/loan/loan/getById",//路径
						data : {id:loanid},//数据，这里使用的是Json格式进行传输
						async:false,
						success : function(data) {//返回数据根据结果进行相应的处理
							if(data&&data.id){
								loanMap[data.id]=data;
							}
						}
					});
				}
				if(loanid in loanMap){
					var loan=loanMap[loanid];
					var html="";
					html+="<div style='padding: 10px;' id='sc_wrap'>";
					html+="<div style='padding-bottom: 10px'>【"+loan.name+"】最低利率："+loan.minRate+" 最高利率："+loan.maxRate+"</div>";
					html+="<div>所需利率为：<input type='text' style='height: 30px;' name='rate' placeholder='请输入利率（小数）'></div>";
					html+="<div><span style='color: red'>(*注：此利率为该客户贷款的最终利率)</span></div>";
					html+=	'<div class="row" style="display: block;margin: 0 auto;width: 200px;margin-top: 30px;">';
					html+=		'<input id="btn_save_rate" data-id="'+id+'" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;&nbsp;&nbsp;';
					html+=		'<input id="btn_cancel_sc" class="btn" type="button" value="取消" />';
					html+='</div>';
					html+="</div>"
					//页面层
					layer.open({
						type: 1,
						title:"设置利率",
						skin: 'layui-layer-rim', //加上边框
						area: ['350px', '250px'], //宽高
						content: html
					});
				}else{
					layer.alert("操作失败，请联系管理员！");
					return;
				}
			});
			$(".set-pay").click(function(){
				var id=$(this).data("id");
				if(!id){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				var html="";
				html+="<div style='padding: 10px;' id='sc_wrap'>";
				html+="<div>所需订金为：<input type='text' style='height: 30px;' name='serviceCharge' placeholder='单位：元'></div>";
				html+="<div><span style='color: red'>(*注：订金为0则客户无需支付定金)</span></div>";
				html+=	'<div class="row" style="display: block;margin: 0 auto;width: 200px;margin-top: 30px;">';
				html+=		'<input id="btn_save_sc" data-id="'+id+'" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;&nbsp;&nbsp;';
				html+=		'<input id="btn_cancel_sc" class="btn" type="button" value="取消" />';
				html+='</div>';
				html+="</div>"
				//页面层
				layer.open({
					type: 1,
					title:"设置订金",
					skin: 'layui-layer-rim', //加上边框
					area: ['350px', '200px'], //宽高
					content: html
				});
			});
			$("body").on("click","#btn_save_rate",function () {
				var id=$(this).data("id");
				if(!id){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				var rate=$(this).closest("#sc_wrap").find("input[name='rate']").val();
				if(!rate){
					layer.alert("请填写利率！");
					return;
				}
				var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
				if(!exp.test(rate)){
					layer.alert("利率只能是整数或小数哦！");
					return;
				}
				var param={};
				param["id"]=id;
				param["rate"]=rate;
				$.ajax({
					type : "POST",  //提交方式
					url : "${ctx}/sys/loan/customPay/saveRate",//路径
					data : param,//数据，这里使用的是Json格式进行传输
					success : function(data) {//返回数据根据结果进行相应的处理
						if(data){
							layer.alert("设置利率成功！",function () {
								window.location.reload();
							});
						}else{
							layer.alert("操作失败",-1);
						}
					}
				});
			});

			$("body").on("click","#btn_save_do_pay",function () {
				var id=$(this).data("id");
				var sc=$(this).data("sc");
				if(!id||!sc){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				var param={};
				param["id"]=id;
				$.ajax({
					type : "POST",  //提交方式
					url : "${ctx}/sys/loan/customPay/payServiceCharge",//路径
					data : param,//数据，这里使用的是Json格式进行传输
					success : function(data) {//返回数据根据结果进行相应的处理
						if(data){
							layer.alert("支付订金成功！",function () {
								window.location.reload();
							});
						}else{
							layer.alert("操作失败",-1);
						}
					}
				});
			});
			$("body").on("click",".do-settlement-pay",function () {
				var id=$(this).data("id");
				if(!id){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				layer.confirm("确认要在后台进行结算付款吗？",function () {
					var param={};
					param["id"]=id;
					$.ajax({
						type : "POST",  //提交方式
						url : "${ctx}/sys/loan/customPay/paySettlement",//路径
						data : param,//数据，这里使用的是Json格式进行传输
						success : function(data) {//返回数据根据结果进行相应的处理
							if(data){
								layer.alert("结算支付成功，贷款成功！",function () {
									window.location.reload();
								});
							}else{
								layer.alert("操作失败",-1);
							}
						}
					});
				});

			});

			$("body").on("click","#btn_save_sc",function () {
				var id=$(this).data("id");
				if(!id){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				var serviceCharge=$(this).closest("#sc_wrap").find("input[name='serviceCharge']").val();
				if(!serviceCharge){
					layer.alert("请填写订金！");
					return;
				}
				var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
				if(!exp.test(serviceCharge)){
					layer.alert("订金只能是整数或小数哦！");
					return;
				}
				var param={};
				param["id"]=id;
				param["serviceCharge"]=serviceCharge;
				$.ajax({
					type : "POST",  //提交方式
					url : "${ctx}/sys/loan/customPay/saveServiceCharge",//路径
					data : param,//数据，这里使用的是Json格式进行传输
					success : function(data) {//返回数据根据结果进行相应的处理
						if(data){
							layer.alert("设置订金成功！",function () {
								window.location.reload();
							});
						}else{
							layer.alert("操作失败",-1);
						}
					}
				});
			});
			$("body").on("click","#btn_cancel_sc",function () {
				layer.closeAll();
			});
			$(".do-settlement").click(function(){
				if(!$(this).data("flm")||"0.0"==$(this).data("flm")){
					layer.alert("请先设置银行实际下款额度",-1);
					return;
				}

				var id=$(this).data("id");
				if(!id){
					layer.alert("操作失败，请联系管理员！",-1);
					return;
				}
				//页面层
				layer.open({
					type: 2,
					title:"结算",
					skin: 'layui-layer-rim', //加上边框
					offset: ['50px', '100px'],
					area: ['900px', '500px'], //宽高
					content: "${ctx}/sys/loan/customPay/load/settlementPage?id="+id
				});
			});


			$(".setflm").click(function(){
				var oldFlm=$(this).data("flm")||0;
				var id=$(this).data("id");
				if(!id){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				var html="";
				html+="<div style='padding: 10px;' id='sc_wrap'>";
				if(oldFlm=="0.0"){
					html+="<div>银行最终下款额度为：<input type='text' style='height: 30px;' name='flm'   placeholder='单位：元'><span >(元)</span></div>";
				}else{
					html+="<div>银行最终下款额度为：<input type='text' style='height: 30px;' name='flm'  value='"+oldFlm+"' placeholder='单位：元'><span >(元)</span></div>";
				}
				html+="<div><span style='color: red'>(*注：请设置银行最终下款额度)</span></div>";
				html+=	'<div class="row" style="display: block;margin: 0 auto;width: 200px;margin-top: 30px;">';
				html+=		'<input id="btn_save_flm" data-id="'+id+'" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;&nbsp;&nbsp;';
				html+=		'<input id="btn_cancel_sc" class="btn" type="button" value="取消" />';
				html+='</div>';
				html+="</div>"
				//页面层
				layer.open({
					type: 1,
					title:"设置银行最终下款额度",
					skin: 'layui-layer-rim', //加上边框
					area: ['350px', '200px'], //宽高
					content: html
				});
			});
			$("body").on("click","#btn_save_flm",function () {
				var id=$(this).data("id");
				if(!id){
					layer.alert("操作失败，请联系管理员！");
					return;
				}
				var flm=$(this).closest("#sc_wrap").find("input[name='flm']").val();
				if(!flm){
					layer.alert("请填写订金！");
					return;
				}
				var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
				if(!exp.test(flm)){
					layer.alert("只能是整数或小数哦！");
					return;
				}
				var param={};
				param["customPayId"]=id;
				param["finishLoanLimit"]=flm;
				$.ajax({
					type : "POST",  //提交方式
					url : "${ctx}/sys/loan/customPay/setFinishLoanLimit",//路径
					data : param,//数据，这里使用的是Json格式进行传输
					success : function(data) {//返回数据根据结果进行相应的处理
						if(data){
							layer.alert("设置银行最终审核额度成功！",function () {
								window.location.reload();
							});
						}else{
							layer.alert("操作失败",-1);
						}
					}
				});
			});
			$("#contentTable").stickyTableHeaders();
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/loan/customPay/">客户申请记录列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="customPay" action="${ctx}/sys/loan/customPay/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
		
			<li><label>用户姓名：</label>
				<form:input path="memberName" htmlEscape="false" maxlength="64" class="input-medium"/>
			</li>
			<li><label>产品名称：</label>
				<form:input path="name" htmlEscape="false" maxlength="255" class="input-medium"/>
			</li>
			<li><label>用户电话：</label>
				<form:input path="memberPhone" htmlEscape="false" maxlength="255" class="input-medium"/>
			</li>
			<li><label>客户经理：</label>
				<form:input path="customServiceName" htmlEscape="false" maxlength="255" class="input-medium"/>
			</li>
			<li><label>申请状态：</label>
				<select name="orderFlag">
					<option value="">=请选择=</option>
					<option value="0" <c:if test="${customPay.orderFlag=='0'}">selected</c:if>>支付订金</option>
					<option value="1" <c:if test="${customPay.orderFlag=='1'}">selected</c:if>>审核中</option>
					<option value="2" <c:if test="${customPay.orderFlag=='2'}">selected</c:if>>结算</option>
					<option value="3" <c:if test="${customPay.orderFlag=='3'}">selected</c:if>>结算付款</option>
					<option value="4" <c:if test="${customPay.orderFlag=='4'}">selected</c:if>>贷款成功</option>
					<%--<option value="5">贷款失败</option>--%>
				</select>
			</li>
			<li><label>申请来源：</label>
				<select name="origin">
					<option value="" <c:if test="${customPay.origin==''}">selected</c:if> >=全部=</option>
					<option value="0"  <c:if test="${customPay.origin=='0'}">selected</c:if>>移动端</option>
					<option value="1"  <c:if test="${customPay.origin=='1'}">selected</c:if>>后台录入</option>
				</select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
		<table id="contentTable" class="table table-striped table-bordered table-condensed">
			<thead style="top: 0">
			<tr>
				<th style="width: 7%">操作</th>
				<shiro:hasPermission name="sys:member:member:sr:view">
					<th style="width: 4%">服务记录</th>
				</shiro:hasPermission>
				<th style="width: 15%">贷款用户</th>
				<th style="width: 5%">产品名称</th>
				<th style="width: 5%">产品渠道</th>
				<th style="width: 5%">申请金额</th>
				<th style="width: 5%">预期会审批额度</th>
				<th style="width: 5%">银行最终下款额度</th>
				<th style="width: 5%">订金</th>
				<th style="width: 5%">商务人员</th>
                <th style="width: 5%">客服人员</th>
				<th style="width: 5%">申请来源</th>
				<th style="width: 5%">申请日期</th>
				<th style="width: 5%">申请状态</th>
			</tr>
			</thead>
			<tbody>
			<c:forEach items="${page.list}" var="customPay">
				<tr style="<c:choose>
				<c:when test="${customPay.orderFlag=='0'}">background:#3498DB !important;</c:when>
				<c:when test="${customPay.orderFlag=='1'}">background:#F39C12 !important;</c:when>
				<c:when test="${customPay.orderFlag=='2'}">background:#9B59B6 !important;</c:when>
				<c:when test="${customPay.orderFlag=='3'}">background:#1ABC9C !important; </c:when>
				<c:when test="${customPay.orderFlag=='4'}">background:#27AE60 !important;</c:when>
				<c:when test="${customPay.orderFlag=='5'}">background:#E74C3C !important;</c:when>
					<c:otherwise></c:otherwise>
						</c:choose>">
					<td style="width: 7%">
						<shiro:hasPermission name="sys:member:member:inputapply"><a  href="${ctx}/sys/loan/customPay/editApplyPage?id=${customPay.id}">编辑</a></shiro:hasPermission>
						<shiro:hasPermission name="sys:loan:customPay:edit">
							<a href="${ctx}/sys/loan/customPay/delete?id=${customPay.id}" onclick="return confirmx('确认要删除该申请吗？', this.href)">删除</a>
						</shiro:hasPermission>
						<c:choose>
							<c:when test="${customPay.orderFlag=='0'}">
								<c:choose>
									<c:when test="${empty customPay.serviceCharge}"><shiro:hasPermission name="sys:loan:customPay:setpay"><a class="set-pay" href="javascript:void(0)"  data-id="${customPay.id}">设置订金</a></shiro:hasPermission></c:when>
									<c:when test="${customPay.serviceCharge==''}"> <shiro:hasPermission name="sys:loan:customPay:setpay"><a class="set-pay" href="javascript:void(0)" data-id="${customPay.id}">设置订金</a></shiro:hasPermission></c:when>
									<c:otherwise></c:otherwise>
								</c:choose>
								<c:choose>
									<c:when test="${empty customPay.rate}"><shiro:hasPermission name="sys:loan:customPay:setrate"><a class="set-rate" href="javascript:void(0)"  data-loanid="${customPay.loanid}" data-id="${customPay.id}">设置利率</a>	</shiro:hasPermission></c:when>
									<c:when test="${customPay.rate==''}"> <shiro:hasPermission name="sys:loan:customPay:setrate"><a class="set-rate" href="javascript:void(0)"  data-loanid="${customPay.loanid}" data-id="${customPay.id}">设置利率</a>	</shiro:hasPermission></c:when>
									<c:otherwise></c:otherwise>
								</c:choose>
								<shiro:hasPermission name="sys:loan:customPay:dopay"><a class="do-pay" href="javascript:void(0)" data-sc="${customPay.serviceCharge}" data-id="${customPay.id}">付订金</a></shiro:hasPermission>
							</c:when>
							<c:when test="${customPay.orderFlag=='1'}">
								<shiro:hasPermission name="sys:loan:customPay:checkloan"><a href="${ctx}/sys/loan/customPay/checkLoanFormPage?customPayId=${customPay.id}&id=${customPay.memberid}&loanId=${customPay.loanid}">审批贷款</a></shiro:hasPermission>
								<shiro:hasPermission name="sys:loan:customPay:checkmaterialclear"><a href="${ctx}/sys/loan/customPay/checkFormPage?id=${customPay.memberid}">审核资料清晰度</a></shiro:hasPermission>
							</c:when>
							<c:when test="${customPay.orderFlag=='2'}">
								<shiro:hasPermission name="sys:loan:customPay:settlement">
									<a class="do-settlement" href="javascript:void(0)" data-flm="${customPay.finishLoanLimit/100}"  data-id="${customPay.id}">结算</a>
									<a class="setflm" href="javascript:void(0)" data-flm="${customPay.finishLoanLimit/100}" data-id="${customPay.id}">设置下款金额</a>
								</shiro:hasPermission>
							</c:when>
							<c:when test="${customPay.orderFlag=='3'}"><shiro:hasPermission name="sys:loan:customPay:settlementpay"><a class="do-settlement-pay" href="javascript:void(0)"  data-id="${customPay.id}">结算付款</a></shiro:hasPermission></c:when>
							<c:otherwise></c:otherwise>
						</c:choose>
					</td>
					<shiro:hasPermission name="sys:member:member:sr:view">
						<td style="width: 4%">
							<a href="#" class="view_service_record" data-id="${customPay.memberid}">查看更多</a>
						</td>
					</shiro:hasPermission>
					<td style="width: 15%">
							${customPay.memberRealName}（<a href="#" href="javascript:void(0)" class="view-info"   data-id="${customPay.id}">${customPay.memberPhone} ${customPay.memberPhoneGeo}</a>）
					</td>
					<td style="width: 5%">
							${customPay.name}
					</td>
					<td style="width: 5%">
							${customPay.loanBankName}
					</td>

					<td style="width: 5%">
						<fmt:formatNumber type="number" value="${customPay.memberLoanLimit/100}" maxFractionDigits="0"/>元
					</td>
					<td style="width: 5%">
						<fmt:formatNumber type="number" value="${customPay.loanLimit/100}" maxFractionDigits="0"/>元
					</td>
					<td style="width: 5%">
						<fmt:formatNumber type="number" value="${customPay.finishLoanLimit/100}" maxFractionDigits="0"/>元
					</td>

					<td style="width: 5%">
						<fmt:formatNumber type="number" value="${customPay.serviceCharge/100}" maxFractionDigits="0"/>元
					</td>
					<td style="width: 5%">
							${customPay.managerName}
					</td>
					<td style="width: 5%">
							${customPay.customServiceName}
					</td>

					<td style="width: 5%">
								<c:choose>
									<c:when test="${customPay.origin=='0'}"><span>移动端</span></c:when>
									<c:when test="${customPay.origin=='1'}"><span >后台录入</span></c:when>
									<c:otherwise>未知</c:otherwise>
								</c:choose>
					</td>
					<td style="width: 5%">
						<fmt:formatDate value="${customPay.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
					</td>
					<td style="width: 5%">
						<c:choose>
							<%--	public final static String WATTINGPAY = "0";// 申请成功,等待支付定金
                                public final static String WAITTINGCHECK = "1";//支付定金成功,等待我们审核
                                public final static String WATTINGSETTLEMENT = "2";//审核通过，等待结算
                                public final static String WATTINGPAYSETTLEMENT = "3";//结算完成，等待付款
                                public final static String LOANSUCCESS = "4";//付款完成，贷款成功
                                public final static String LOANFAILED = "5";//贷款失败--%>
							<c:when test="${customPay.orderFlag=='0'}"><span<%-- style="color:red"--%>>支付订金</span></c:when>
							<c:when test="${customPay.orderFlag=='1'}"><span <%--style="color:green"--%>>审核中</span></c:when>
							<c:when test="${customPay.orderFlag=='2'}"><span<%-- style="color:green"--%>>结算</span></c:when>
							<c:when test="${customPay.orderFlag=='3'}"><span <%--style="color:red"--%>>结算付款</span></c:when>
							<c:when test="${customPay.orderFlag=='4'}"><span <%--style="color:green"--%>>贷款成功</span></c:when>
							<c:when test="${customPay.orderFlag=='5'}"><span <%--style="color:red"--%>>贷款失败</span></c:when>
							<c:otherwise></c:otherwise>
						</c:choose>
					</td>
				</tr>
			</c:forEach>
			</tbody>
		</table>
		<div class="pagination">${page}</div>


</body>
</html>